{% load i18n %}
{% load markup %}

{% with field_count=table.headers|length row_count=table.rows|length %}
<thead>

    {% block table_headers %}
    <tr>
        {% join '_' table.uid 'order_by' as order_by_key %}
        {% for h in table.headers %}
        {% block table_header %}
        <td class="{{ h.type }}">
            {{ h.name|capfirst }}
            {% if h.attname in table.order_by %}
            <a class="asc" href="{{ request.path }}?{% for k, v in request.GET.items %}{% if k != order_by_key %}{{ k }}={{ v }};{% endif %}{% endfor %}{{ order_by_key }}=-{{ h.attname }}">&#9652;</a>
            {% else %}
            <a class="desc" href="{{ request.path }}?{% for k, v in request.GET.items %}{% if k != order_by_key %}{{ k }}={{ v }};{% endif %}{% endfor %}{{ order_by_key }}={{ h.attname }}">&#9662;</a>
            {% endif %}
        </td>
        {% endblock %}
        {% endfor %}
        <td class="actions">{% trans "Actions" %}</td>
    </tr>
    {% endblock %}
    
</thead>

{% if row_count %}
<tbody>
    {% for row in table.rows %}
    <tr{% cycle '' ' class="altrow"' %}>
        {% for f in row.fields %}
        {% with field_index=forloop.counter0 %}
        {% block table_field %}
        {% if field_index == 0 %}
        <td>
            {% block table_first_column %}<strong>{{ f }}</strong>{% endblock %}
        </td>
        {% else %}
        <td>
            {% block table_column %}{{ f }}{% endblock %}
        </td>
        {% endif %}
        {% endblock %}
        {% endwith %}
        {% endfor %}
        <td>
            {% block table_field_actions %}
            {% endblock %}
        </td>
    </tr>
    {% endfor %}
</tbody>
{% endif %}

{% block table_footer %}
<tfoot>
    <tr><td colspan="{{ field_count }}"><strong>{% blocktrans with total_count=paginator.count %}{{ row_count }} of {{ total_count }} items{% endblocktrans %}</strong></td></tr>
</tfoot>
{% endblock %}

{% endwith %}
